//
//  SEGInviteManager.m
//  ExcellentHome
//
//  Created by 揭婧雯 on 2017/3/3.
//  Copyright © 2017年 陈区. All rights reserved.
//

#import "SEGInviteManager.h"

@implementation SEGInviteManager
/// 请求邀请邻居入口数据
-(void)requestShareEntryInfo:(SEGNetworkReponse)finished
{
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/uhomecp-app/share-api/v1/shareEntryInfo.json",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:nil finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
       
        if (!isSuccessed) {
            finished(NO,result, @"", kNetworkErrorMessage); //数据返回异常
            return;
        }
        
        NSDictionary* data = [result valueForKey:@"data"];
        if (data && [data isKindOfClass:[NSDictionary class]]) {
            self.inviteModel = [SEGInviteModel initWithDictionary:data];
        }else {
            finished(NO,result, @"", @"");
            return;
        }
        
        finished(YES,result, codeType, errorMessage);
    }];
}

/// 请求提交分享记录
-(void)requestSubmitShareQcodeWithShareCode:(NSString *)shareCode paperId:(NSString *)paperId channel:(NSString *)channel finished:(SEGNetworkReponse)finished
{
    NSDictionary *params = @{@"shareCode":shareCode,@"paperId":paperId,@"channel":channel};
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/uhomecp-app/share-api/v1/submitShareQcode.json",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:params finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        finished(isSuccessed,result, codeType, errorMessage);
    }];
}

/// 请求邀请记录
-(void)requesthareRecordListWithPageNo:(NSString *)pageNo pageSize:(NSString *)pageSize finished:(SEGNetworkReponse)finished
{
    NSDictionary *params = @{@"pageNo":pageNo,@"pageSize":pageSize};
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/uhomecp-app/share-api/v1/shareRecordList.json",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:params finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        
        if (!isSuccessed) {
            finished(NO,result, @"", kNetworkErrorMessage); //数据返回异常
            return;
        }
        
        NSDictionary* data = [result valueForKey:@"data"];
        if (data && [data isKindOfClass:[NSDictionary class]]) {
            self.recordModel = [SEGInviteRecordModel initWithDictionary:data];
        }
        
        finished(YES,result, codeType, errorMessage);
    }];
}

/// 请求话费提交手机号
-(void)requestSubmitPhoneByChargeWithWinId:(NSString *)winId phone:(NSString *)phone finished:(SEGNetworkReponse)finished
{
    NSDictionary *params = @{@"winId":winId,@"phone":phone};
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/uhomecp-app/share-api/v1/submitPhoneByCharge.json",nil];
    
    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:params finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        
        if (!isSuccessed) {
            finished(NO,result, @"", kNetworkErrorMessage); //数据返回异常
            return;
        }
        
        NSDictionary* data = [result valueForKey:@"data"];
        if (data && [data isKindOfClass:[NSDictionary class]]) {
            self.recordModel = [SEGInviteRecordModel initWithDictionary:data];
        }
        
        finished(YES,result, codeType, errorMessage);
    }];
}
@end
